package com.parsechina.hpush.rest.account.service.impl;

import com.parsechina.hpush.rest.account.domain.Account;
import com.parsechina.hpush.rest.account.domain.AccountExample;
import com.parsechina.hpush.rest.account.mapper.AccountMapper;
import com.parsechina.hpush.rest.account.service.AccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author linfeng
 * @date 2019-08-23
 **/
@Service
public class AccountServiceImpl implements AccountService {

    private final AccountMapper accountMapper;

    @SuppressWarnings("SpringJavaInjectionPointsAutowiringInspection")
    @Autowired
    public AccountServiceImpl(AccountMapper accountMapper) {
        this.accountMapper = accountMapper;
    }

    @Override
    public boolean save(Account record) {
        int recordCount;
        if (record.getId() == null) {
            recordCount = accountMapper.insertSelective(record);
        } else {
            AccountExample example = new AccountExample();
            example.createCriteria().andIdEqualTo(record.getId());
            recordCount = accountMapper.updateByExampleSelective(record, example);
        }
        return recordCount > 0;
    }
}
